<%@ page import="org.sky.autoconfigure.factory.SkyPropertiesFactory" %>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <!-- 放在第一行 兼容低版本IE-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta charset="UTF-8">
    <title>系统登录</title>
    <c:url value="/" var="basepath"></c:url>
    <c:set value="jquery-easyui-1.5.4.5" var="easyui"></c:set>
    <script type="text/javascript">
        var basepath='${basepath}';
    </script>
    <!--好像必须16*16-->
    <link rel="shortcut icon" href="${basepath}static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" type="text/css" href="${basepath}static/plugins/${easyui}/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="${basepath}static/plugins/easyui-css/IconExtension.css"/>
    <link rel="stylesheet" type="text/css" href="${basepath}static/css/sky.css"/>

    <script type="text/javascript" src="${basepath}static/plugins/jquery/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="${basepath}static/plugins/jquery/jquery.cookie.js"></script>
    <script type="text/javascript" src="${basepath}static/plugins/${easyui}/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${basepath}static/plugins/${easyui}/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${basepath}static/js/md5.js"></script>
    <style type="text/css">
        body {
            background-size: cover;
            overflow-x: hidden;
            overflow-y: hidden;
            background-color: #2E4356;
        }
        .login_button {
            width: 93px;
            height: 30px;
            padding: 0px;
            border: 0px;
            font-size: 14px;
        }
        .login_form {
            width: 500px;
            height: 300px;
            position: absolute;
            text-align: center;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
            border-radius: 2px;
        }

        /*table单元格默认值*/
        table{
            width:100%;
            text-align: center;
            border-collapse:separate;
            border-spacing:10px;
        }
        table tr{
            text-align: center;
            margin: 10px auto;
            padding: auto;
        }
        table tr th{
            border:0px solid #82B3E1;
        }
        table tr td{
            border:0px solid #82B3E1;
            text-align: center;
        }
        .title{
            color:#FFFFFF;
            font-size: 23px;
            font-weight:400;
            padding-top:15px;
        }
        .textbox{
            border-top: 0px solid;
            border-left: 0px solid;
            border-right: 0px solid;
        }
    </style>
</head>
<body>
<form id="loginform" action="${basepath}j_spring_security_check" method="post" class='login_form'>
    <table>
        <tr>
            <td>
                <h1 class='title'><%=SkyPropertiesFactory.getSkyProperties().getProductName() %></h1>
            </td>
        </tr>
        <tr>
            <td>
                <input class="easyui-textbox"  name="username" id="j_username" value=''
                       data-options="prompt:'请输入登录用户名',value:'',
				  				required:true,
				  				novalidate:true,
				  				iconCls:'icon-user_key',
				  				iconAlign:'left',
				  				iconWidth:30"
                       style="width:250px;height:32px;"
                />
            </td>
        </tr>

        <tr>
            <td>
                <input class="easyui-textbox" type="password"  name="password" id="j_password" value=''
                       data-options="prompt:'请输入登录密码',value:'',
				   				 required:true,
				   				 novalidate:true,
				   				 iconCls:'icon-key',
				  				 iconAlign:'left',
				  				 iconWidth:30"
                       style="width:250px;height:32px;"
                />
            </td>
        </tr>
        <tr>
            <td style="text-align: center;color:#FFFFFF" colspan='2'>
                <input id="rememberme" type="checkbox"/>记住我
            </td>
        </tr>
        <tr>
            <td style="text-align: center;" colspan='2'>
                <input type='button' id="login_submit" value='登录' class="primary login_button"  onclick='login()'></input>
            </td>
        </tr>
        <tr>
            <td colspan='2' style="text-align: center;">
                <font color=red>${SPRING_SECURITY_LAST_EXCEPTION.message}</font>
            </td>
        </tr>
    </table>
</form>
</body>
<script type="text/javascript">
    function login() {
        var validate = $("#j_username").textbox('enableValidation').textbox('isValid');
        if(!validate)return ;
        var validate = $("#j_password").textbox('enableValidation').textbox('isValid');
        if(!validate)return ;
        $("#j_password").textbox('setValue',hex_md5($("#j_password").textbox('getValue')));
        $("#loginform").submit();
    }
    $(function(){
        initRememberMe();
        $(document).keypress(function(e) {
            // 回车键事件
            if(e.which == 13){
                $('#login_submit').click();
            }
        });
        //用户名录入框获取光标
        $('#j_username').textbox().next('span').find('input').focus();
    });
    //记住密码操作
    function initRememberMe(){
        if($.cookie('absms_crm2_username')!=undefined){
            $("#rememberme").attr("checked", true);
        }else{
            $("#rememberme").attr("checked", false);
        }

        //读取cookie
        if($('#rememberme:checked').length>0){
            $('#j_username').textbox('setValue',$.cookie('absms_crm2_username'));
            $('#j_password').textbox('setValue',$.cookie('absms_crm2_password'));
        }

        //监听【记住我】事件
        $("#rememberme").click(function(){
            if($('#rememberme:checked').length>0){//设置cookie
                $.cookie('absms_crm2_username', $('#j_username').textbox('getValue'),{ path: '/', expires: 10 });
                $.cookie('absms_crm2_password', $('#j_password').textbox('getValue'),{ path: '/', expires: 10 });
            }else{//清除cookie
                $.removeCookie('absms_crm2_username',{ path: '/', expires: 10 });
                $.removeCookie('absms_crm2_password',{ path: '/', expires: 10 });
            }
        });
    }
</script>
</html>